package com.softhis.rekrutacja.client.view.widgets.impl;

import java.util.Date;

import com.extjs.gxt.ui.client.widget.form.DateField;
import com.google.gwt.i18n.client.DateTimeFormat;
import com.google.gwt.user.client.Element;
import com.softhis.rekrutacja.client.view.widgets.interfaces.IDateField;

/**
 *
 * @author Sasak
 */
public class MyGxtDateField extends DateField implements IDateField {

    private Date passedDate = null;

    public MyGxtDateField() {
        super();
    }

    public MyGxtDateField(Date dateToSet){
        super();
        this.passedDate = dateToSet;
    }

    @Override
    protected void onRender(Element target, int index) {
        super.onRender(target, index);
        this.getDatePicker().setValue((passedDate == null) ? new Date() : passedDate);
//        Log.trace("[RENDERING TRAC DATE FIELD]");
    }

    public void setDate(Date date) {
        getDatePicker().setValue(date);
    }

    public void setDateFormat(DateTimeFormat format) {
        getPropertyEditor().setFormat(format);
    }

    @Override
    public void reset() {
        setDate(new Date());
    }
    
}
